<?php
class ModelVoucherOrderdetailtemp extends Model 
{
	public function getList($where)
	{
		$query = $this->db->query("Select * from `order_detail_temp` where 1=1 ".$where);
		return $query->rows;
	}
	
	public function getItem($orderdetailid)
	{
		$query = $this->db->query("Select * from `order_detail_temp` where orderdetailid = '".$orderdetailid."'");
		return $query->row;
	}
	
	public function saveorderdetail($data)
	{
		$orderdetailid=$this->db->escape(@$data['orderdetailid']);
		$orderid=$this->db->escape(@$data['orderid']);
		$orderdetailno=$this->db->escape(@$data['orderdetailno']);
		$productid=$this->db->escape(@$data['productid']);
		$barcode=$this->db->escape(@$data['barcode']);
		$productname=$this->db->escape(@$data['productname']);
		$stockid=$this->db->escape(@$data['stockid']);
		$qty=$this->db->escape(@$data['qty']);
		$importqty=$this->db->escape(@$data['importqty']);
		$exportqty=$this->db->escape(@$data['exportqty']);
		$unit=$this->db->escape(@$data['unit']);
		$netprice=(float)(@$data['netprice']);
		$saleprice=(float)(@$data['saleprice']);
		$orderprice=(float)(@$data['orderprice']);
		$subtotal=(float)(@$data['subtotal']);
		$tax=(float)(@$data['tax']);
		$taxamount=(float)(@$data['taxamount']);
		$grandtotal=(float)(@$data['grandtotal']);
		$discount=(float)(@$data['discount']);
		$discountamount=(float)(@$data['discountamount']);
		$note=$this->db->escape(@$data['note']);
		$expireddate=$this->db->escape(@$data['expireddate']);
		$warranty=$this->db->escape(@$data['warranty']);
		
		$field=array(
						'orderid',
						'orderdetailno',
						'productid',
						'barcode',
						'productname',
						'stockid',
						'qty',
						'importqty',
						'exportqty',
						'unit',
						'netprice',
						'saleprice',
						'orderprice',
						'subtotal',
						'tax',
						'taxamount',
						'grandtotal',
						'discount',
						'discountamount',
						'note',
						'expireddate',
						'warranty'
					);
		$value=array(
						$orderid,
						$orderdetailno,
						$productid,
						$barcode,
						$productname,
						$stockid,
						$qty,
						$importqty,
						$exportqty,
						$unit,
						$netprice,
						$saleprice,
						$orderprice,
						$subtotal,
						$tax,
						$taxamount,
						$grandtotal,
						$discount,
						$discountamount,
						$note,
						$expireddate,
						$warranty
					);
		
		$orderdetail = $this->getItem($orderdetailid);
		if(count($orderdetail) > 0)
		{
			$where="orderdetailid = '".$orderdetailid."'";
			$this->db->updateData("order_detail_temp",$field,$value,$where);
			return $orderid;
		}
		else
		{
			return $this->db->insertData("order_detail_temp",$field,$value);	
		}
	}
	
	public function insert($data)
	{
		$orderdetailid=$this->db->escape(@$data['orderdetailid']);
		$orderid=$this->db->escape(@$data['orderid']);
		$orderdetailno=$this->db->escape(@$data['orderdetailno']);
		$productid=$this->db->escape(@$data['productid']);
		$productname=$this->db->escape(@$data['productname']);
		$stockid=$this->db->escape(@$data['stockid']);
		$qty=$this->db->escape(@$data['qty']);
		$importqty=$this->db->escape(@$data['importqty']);
		$exportqty=$this->db->escape(@$data['exportqty']);
		$unit=$this->db->escape(@$data['unit']);
		$netprice=(float)(@$data['netprice']);
		$saleprice=(float)(@$data['saleprice']);
		$orderprice=(float)(@$data['orderprice']);
		$subtotal=(float)(@$data['subtotal']);
		$tax=(float)(@$data['tax']);
		$taxamount=(float)(@$data['taxamount']);
		$grandtotal=(float)(@$data['grandtotal']);
		$discount=(float)(@$data['discount']);
		$discountamount=(float)(@$data['discountamount']);
		$note=$this->db->escape(@$data['note']);
		$expireddate=$this->db->escape(@$data['expireddate']);
		$warranty=$this->db->escape(@$data['warranty']);
		
		$field=array(
						'orderid',
						'orderdetailno',
						'productid',
						'barcode',
						'productname',
						'stockid',
						'qty',
						'importqty',
						'exportqty',
						'unit',
						'netprice',
						'saleprice',
						'orderprice',
						'subtotal',
						'tax',
						'taxamount',
						'grandtotal',
						'discount',
						'discountamount',
						'note',
						'expireddate',
						'warranty'
					);
		$value=array(
						$orderid,
						$orderdetailno,
						$productid,
						$barcode,
						$productname,
						$stockid,
						$qty,
						$importqty,
						$exportqty,
						$unit,
						$netprice,
						$saleprice,
						$orderprice,
						$subtotal,
						$tax,
						$taxamount,
						$grandtotal,
						$discount,
						$discountamount,
						$note,
						$expireddate,
						$warranty
					);
		$this->db->insertData("order_detail_temp",$field,$value);
	}
	
	public function update($data)
	{
		$orderdetailid=$this->db->escape(@$data['orderdetailid']);
		$orderid=$this->db->escape(@$data['orderid']);
		$orderdetailno=$this->db->escape(@$data['orderdetailno']);
		$productid=$this->db->escape(@$data['productid']);
		$productname=$this->db->escape(@$data['productname']);
		$stockid=$this->db->escape(@$data['stockid']);
		$qty=$this->db->escape(@$data['qty']);
		$importqty=$this->db->escape(@$data['importqty']);
		$exportqty=$this->db->escape(@$data['exportqty']);
		$unit=$this->db->escape(@$data['unit']);
		$netprice=(float)(@$data['netprice']);
		$saleprice=(float)(@$data['saleprice']);
		$orderprice=(float)(@$data['orderprice']);
		$subtotal=(float)(@$data['subtotal']);
		$tax=(float)(@$data['tax']);
		$taxamount=(float)(@$data['taxamount']);
		$grandtotal=(float)(@$data['grandtotal']);
		$discount=(float)(@$data['discount']);
		$discountamount=(float)(@$data['discountamount']);
		$note=$this->db->escape(@$data['note']);
		$expireddate=$this->db->escape(@$data['expireddate']);
		$warranty=$this->db->escape(@$data['warranty']);
		
		$field=array(
						'orderid',
						'orderdetailno',
						'productid',
						'barcode',
						'productname',
						'stockid',
						'qty',
						'importqty',
						'exportqty',
						'unit',
						'netprice',
						'saleprice',
						'orderprice',
						'subtotal',
						'tax',
						'taxamount',
						'grandtotal',
						'discount',
						'discountamount',
						'note',
						'expireddate',
						'warranty'
					);
		$value=array(
						$orderid,
						$orderdetailno,
						$productid,
						$barcode,
						$productname,
						$stockid,
						$qty,
						$importqty,
						$exportqty,
						$unit,
						$netprice,
						$saleprice,
						$orderprice,
						$subtotal,
						$tax,
						$taxamount,
						$grandtotal,
						$discount,
						$discountamount,
						$note,
						$expireddate,
						$warranty
					);
		
					
		$where="orderdetailid = '".$orderdetailid."'";
		$this->db->updateData("order_detail_temp",$field,$value,$where);
	}	
			
	public function delete($orderdetailid)
	{
		$orderdetailid=$this->db->escape(@$orderdetailid);
		$where="orderdetailid = '".$orderdetailid."'";
		$this->db->deleteData('order_detail_temp',$where);
	}
	
	public function deleteorder($orderid)
	{
		$orderid=$this->db->escape(@$orderid);
		$where="orderid = '".$orderid."'";
		$this->db->deleteData('order_detail_temp',$where);
	}
	
	public function deletes($data)
	{
		foreach($data as $orderdetailid)
		{
			$this->delete($orderdetailid);
		}		
	}
	
}

?>